package com.neotech.rdf;

import java.net.URI;
import java.net.URISyntaxException;

import javax.ws.rs.core.UriBuilder;

import org.apache.log4j.Logger;
import org.neo4j.graphdb.Node;

import com.neotech.neo4j.Neo4j;
import com.neotech.neo4j.utils.Constants;

public class RDFToolkit {
	private static Logger log = Logger.getLogger(RDFToolkit.class.getName());

	private Neo4j server;
	
	public RDFToolkit(Neo4j server){
		this.server = server;
		log.debug(":: Created RDF toolkit :: ");
	}
	
	public Long createNode(String uri) {
		if(!isValidUri(uri))
			return null;
		Long node = server.createNode();
		server.addPropertyToNode(node, Constants.URI, uri.toString());
		log.debug(":: Created node with uri: "+uri+" :: ");
		return node;
	}
	
	private boolean isValidUri(String uri){
		try {
			new URI(uri);
			return true;
		} catch (URISyntaxException e) {
			log.debug("Invalid URI");
			return false;
		}
	}
	

}
